package edu.zzuli.servlet;

import edu.zzuli.pojo.User;
import edu.zzuli.service.RegeistService;
import edu.zzuli.service.impl.RegeistServiceImpl;
import edu.zzuli.utils.UUidUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.UUID;

/**
 * Created by Chen-D.W on 2017/12/25.
 * 注册servlet
 */
public class regeist extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        String mail=request.getParameter("mail");
        User user=new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setMail(mail);
        user.setStatus(0);
        String code= UUidUtil.getUUid()+UUidUtil.getUUid();
        user.setCode(code);
        RegeistService regeistService=new RegeistServiceImpl();
        try {
            regeistService.createdUser(user);
            response.sendRedirect("success.jsp");
        } catch (SQLException e) {
            response.sendRedirect("fail.jsp");
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
